<template>
	<view class="main">
		<ul>
			<li>
				<view class="msg">
					我的头像
				</view>
				<view class="avatar">
					<image :src="seleUrl" mode=""></image>
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li>
				<view class="msg">
					手机号
				</view>
				<view class="txt">
					{{userInfo.mobile}}
				</view>
			</li>
			<li>
				<view class="msg">
					昵称
				</view>
				<view class="txt">
					{{userInfo.nickname}}
				</view>
			</li>
			<li @tap="routerTo('/pages/pageB/function/upInfo')">
				<view class="msg">
					修改信息
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li @tap="routerTo('/pages/pageB/changePas/changePas')">
				<view class="msg">
					修改密码
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li @tap="routerTo('/pages/my/UserAgreement')">
				<view class="msg">
					用户协议
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li @tap="routerTo('/pages/my/PrivacyAgreement')">
				<view class="msg">
					隐私协议
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li @tap="show = true">
				<view class="msg">
					注销账号
				</view>
				<image class="right" src="@/static/img/right.png" mode=""></image>
			</li>
			<li>
				<view class="msg">
					版本号
				</view>
				<view class="msg">
					{{version}}
				</view>
			</li>
		</ul>
		<u-notify message="APP需要您的同意才能使用相册或摄像头,以便于上传头像" :show="show1" ref="uNotify"></u-notify>
		<u-modal :show="show" :content='content' :showCancelButton="true" @confirm="hidden"
			@cancel="show = false"></u-modal>
		<view class="btn" @tap="outLogin">
			退出登录
		</view>
	</view>
</template>

<script>
	import {
		userInfo
	} from '@/api/my.js'
	import {
		getConfigs,
		goHidden
	} from '@/api/user.js'
	export default {
		data() {
			return {
				userInfo: {},
				seleUrl: '',
				version: '',
				show: false,
				content: '注销后账号无法继续使用，确认注销吗？',
				show1: true
			}
		},
		onLoad() {
			getConfigs({
				name: 'version'
			}).then((res) => {
				this.version = res.data.value
			});
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			async hidden() {
				uni.removeStorageSync('token')
				let res = await goHidden()
				if (res.code == 1) {
					uni.showToast({
						title: '注销成功',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			upload() {
				this.$refs.uNotify.show({
					top: 0,
					type: 'error',
					color: '#000',
					bgColor: '#fff',
					message: 'APP需要您的同意才能使用相册或摄像头,以便于上传头像',
					duration: 0,
					fontSize: 16,
					safeAreaInsetTop: true
				})
				uni.chooseImage({
					count: 1,
					success: (res) => {
						this.seleUrl = res.tempFilePaths[0]
						// this.uploadFilePromise(this.seleUrl)
					}
				})
			},
			async getUserInfo() {
				let res = await userInfo()
				this.userInfo = res.data
				this.seleUrl = res.data.avatar
			},
			outLogin() {
				uni.removeStorageSync('token')
				uni.showToast({
					title: '退出成功'
				})
				let time = setTimeout(() => {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}, 1000)
			},
			routerTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		height: calc(100vh - 44px);
		background-color: #F9FBFC;

		ul {
			width: 100%;
			background-color: #fff;
			margin-bottom: 15px;

			li {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10px 20px;
				color: #3D3D3D;
				position: relative;

				.avatar {
					image {
						width: 27px;
						height: 27px;
						border-radius: 100px;
					}
				}

				.txt {
					color: #3D3D3D;
				}

				.right {
					width: 15px;
					height: 15px;
					position: absolute;
					right: 10px;
				}
			}

			li:first-child {
				padding-right: 30px;
			}
		}

		.btn {
			width: 100%;
			text-align: center;
			color: #3D3D3D;
			padding: 15px 0;
			background-color: #fff;
		}
	}
</style>